<?php

namespace app\common\model;

use think\Model;


class Coupon extends Model
{

    CONST SYSTEM_YES = 1;
    CONST SYSTEM_NO = 0;
    CONST SHELVES_YES = 1;
    CONST SHELVES_NO = 0;
    // 优惠券类型 全场满减
    CONST TYPE_FULL = 1;
    // 优惠券类型 折扣
    CONST TYPE_DISCOUNT = 2;

    // 优惠券详情  组队
    CONST DETAIL_TEAM = 1;
    // 优惠券详情  赛事
    CONST DETAIL_MATCH = 2;
    // 优惠券详情  充值
    CONST DETAIL_RECHARGE = 3;
    // 优惠券详情  玩家
    CONST DETAIL_PLAYER = 4;

    // 表名
    protected $name = 'coupon';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'detail_text',
        'create_time_text',
        'update_time_text'
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getDetailList()
    {
        return ['1' => __('Detail 1'), '2' => __('Detail 2'), '3' => __('Detail 3'), '4' => __('Detail 4')];
    }

    public function getShelvesList()
    {
        return ['0' => __('Shelves 0'), '1' => __('Shelves 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDetailTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['detail']) ? $data['detail'] : '');
        $list = $this->getDetailList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
